#include "EnemyManager.h"
#include "GameUtil.h"
#include "Enemy1.h"
#include "Enemy2.h"
#include "Enemy3.h"
#include "Boss1.h"
using namespace cocos2d;

EnemyManager::EnemyManager(CCLayer* layer)
{
	_layer = layer;
	CCLabelTTF* waveLabel = CCLabelTTF::create();
	//waveLabel->setOpacity(0);
	layer->addChild(waveLabel);

	//todo
	_enemys = new CCArray;
	_winSize = CCDirector::sharedDirector()->getWinSize();  

}

EnemyManager::~EnemyManager(void)
{
	//_fishs->release();
}

void EnemyManager::removeEnemy(Enemy* enemy){
	_enemys->removeObject(enemy);
	_layer->removeChild(enemy);

	if(_enemys->count() == 0) {
		if(GameUtil::instance()->getWaveManager()->getIsSpawnEnd()) {
			GameUtil::instance()->waveEnded();
		}
	}
}

bool EnemyManager::spawn(EEnemyType type, CCPoint pos)
{
	//if(_enemys->count() >= MAX_ENEMY) {
	//	return false;
	//}

	Enemy* enemy = NULL;
	switch(type) {
	case ENEMY_TYPE_1:
		 enemy = Enemy1::create();
		break;
	case ENEMY_TYPE_2:
		 enemy = Enemy2::create();
		break;
	case ENEMY_TYPE_3:
		 enemy = Enemy3::create();
		break;
	case BOSS1:
		enemy = Boss1::create();
		break;
	default:
		return false;
		break;
	}

	_enemys->addObject(enemy);
	_layer->addChild(enemy);
	enemy->spawn(pos);

	return true;
}
